using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[RequireComponent(typeof(Button))]
public class PushButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IEventSystemHandler
{
	[Serializable]
	public class EditorReferences
	{
		public RectTransform buttonTransform;

		public Vector2 upPosition = new Vector2(0f, 16f);

		public Vector2 downPosition = new Vector2(0f, 9f);
	}

	[SerializeField]
	public EditorReferences references = new EditorReferences();

	private Button _button;

	private void Awake()
	{
		_button = GetComponent<Button>();
	}

	private void OnEnable()
	{
		OnTouchRelease();
	}

	private void OnTouchPress()
	{
		if (_button.interactable)
		{
			references.buttonTransform.anchoredPosition = references.downPosition;
		}
	}

	private void OnTouchRelease()
	{
		references.buttonTransform.anchoredPosition = references.upPosition;
	}

	public void OnPointerDown(PointerEventData eventData)
	{
		OnTouchPress();
	}

	public void OnPointerUp(PointerEventData eventData)
	{
		OnTouchRelease();
	}
}
